﻿using System.Web;
using cludg.Infrastructure.Core.Logging;
using cludg.Infrastructure.Core.Settings;
using cludg.Infrastructure.DI;
using cludg.Infrastructure.DI.Unity;

namespace nsadv.Statistic.Web
{
	public class InjectionsConfiguration : BaseInjectionConfiguration
	{
		public override IDIContainer CreateContainer(HttpApplication application)
		{
			IDIContainer container = new DIContainer();

			// Registrations

			// DI container
			container.RegisterInstance<IDIContainer>(container);

			// Logging
			container.RegisterInstance<ILogger>(new Log4NetLogger("nsadv.Statistic.WebApp"));
	
			// Settings
			container.RegisterInstance<ISettings>(Properties.Settings.Default);

			// Bootstrappers
			container.Register<Bootstrappers.IBootstrapper, Bootstrappers.ControllerFactoryBootstrapper>("ControllerFactory", DILifetime.PerResolve);
			container.Register<Bootstrappers.IBootstrapper, Bootstrappers.RoutesBootstrapper>("Routes", DILifetime.PerResolve);
			container.Register<Bootstrappers.IBootstrapper, Bootstrappers.UpdateDatabaseBootstrapper>("UpdateDatabase", DILifetime.PerResolve);
			container.Register<Bootstrappers.IBootstrapper, Bootstrappers.TestDataBootstrapper>("TestData", DILifetime.PerResolve);

			// Notifications
			container.Register<Notifications.Application.IApplicationNotificationSource, Notifications.Application.ApplicationNotifier>(DILifetime.Singleton);
			container.Register<Notifications.Application.IApplicationNotifier, Notifications.Application.ApplicationNotifier>(DILifetime.Singleton);

			// Repository
			container.Register<Repository.ITransactionFactory, Repository.NHibernate.Transactions.TransactionFactory>(DILifetime.Singleton);
			container.Register<Repository.NHibernate.Sessions.INHibernateSessionController, Sessions.NHibernateSessionController_PerHttpSession>(DILifetime.Singleton);
			container.Register(typeof(Repository.IRepository<>), typeof(Repository.NHibernate.Repository<>),null, DILifetime.Singleton, null);
			container.Register<Repository.IStatistic, Repository.NHibernate.Statistic>(DILifetime.Singleton);

			return container;
		}
	}
}